package com.woniuxy.confirm;

import com.rabbitmq.client.*;
import com.woniuxy.utils.Utils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConfirmConsume1 {
    public static void main(String[] args) throws IOException, TimeoutException {
        //获取连接
        Connection connection = Utils.getConnection();
        //打通通道
        Channel channel = connection.createChannel();
        //消费者绑定队列，并进行消费业务
        channel.basicConsume("confirmQue",false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("ConfirmConsume1 接收消息："+new String(body));
                //手动提交
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        });
    }
}
